# syntax=docker/dockerfile:1
FROM node:18-alpine AS build

WORKDIR /app

ARG NPM_REGISTRY=https://registry.npmjs.org
ARG PNPM_REGISTRY=${NPM_REGISTRY}

ENV NPM_CONFIG_REGISTRY=${NPM_REGISTRY}
ENV PNPM_REGISTRY=${PNPM_REGISTRY}

COPY my-react-app/pnpm-lock.yaml my-react-app/package.json ./
RUN corepack enable \
    && pnpm config set registry ${PNPM_REGISTRY} \
    && pnpm install --frozen-lockfile

COPY my-react-app .

ARG VITE_API_BASE_URL="/api/v1"
ENV VITE_API_BASE_URL=${VITE_API_BASE_URL}
RUN pnpm build \
    && cp -r dist/static/. dist/ \
    && rm -rf dist/static

FROM nginx:alpine
WORKDIR /usr/share/nginx/html
COPY --from=build /app/dist ./
COPY my-react-app/nginx.conf /etc/nginx/conf.d/default.conf

EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
